package com.mapreduce.flowcomparablepartition;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;
//按照省份来分区 （依据 手机前三位）
public class ProvincePartitioner extends Partitioner<FlowBean, Text> {
    public int getPartition(FlowBean flowBean, Text text, int numPartitions) {
        // 1 获取手机号码前三位
        String preNum = text.toString().substring(0, 3);
        int partitionNum;
        switch (preNum){
            case "136":
                partitionNum=0;
                break;
            case "137":
                partitionNum=1;
                break;
            case "138":
                partitionNum=2;
                break;
            case "139":
                partitionNum=3;
                break;
            default:
                partitionNum=4;
                break;
        }
        return partitionNum;
    }
}
